package edu.zju.udms.dnavigator.core.repository;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.apache.lucene.search.Query;

import edu.zju.udms.dnavigator.core.entity.Entity;
import edu.zju.udms.dnavigator.core.entity.MetaObject;
import edu.zju.udms.dnavigator.core.entity.Record;
import edu.zju.udms.dnavigator.core.entity.Relation;

public interface Repository {
	
	public void truncreateEntities(Collection<Entity> entityList) throws Exception;
	public void updateEntity(Entity entity) throws Exception;
	public void truncreateRelations(Collection<Relation> relationList) throws Exception;
	public void createRelations(Collection<Relation> relationList) throws Exception;
	public void truncreateRecords(Collection<Record> recordList) throws Exception;
	public void appendRecords(Collection<Record> recordList) throws Exception;
 
	/* 另一种思路 */
	public void persist(Collection<? extends MetaObject> metalist) throws Exception;
	
	/**
	 * 过滤出符合条件的实体集合
	 * */
	public <T extends MetaObject> List<T> filter(Class<T> clazz,String field,Object value,int size);
	
	public <T extends MetaObject> List<T> filter(Class<T> clazz,Map<String,Object> conditions,int size);
	
	public List<Record> filterRecords(Map<String, Object> conditions, int size);
	
	public List<Map<String, String>> filterRecords2Map(Map<String, Object> conditions, int size);
	
	public List<Relation> filter(Entity from,Entity to,String label,int size);
	
	/**过滤出符合条件的实体的最新版本，调用者自己确保过滤出的实体只有一个*/
	public <T extends MetaObject> T filterLast (Class<T> clazz,String field,Object value);
	
	public <T extends MetaObject> T filterLast (Class<T> clazz,Map<String,Object> conditions);
	
	/**过滤出符合条件的实体的最新版本的ID，调用者自己确保过滤出的实体只有一个*/
	public String filterLastID (Class<?> clazz,String field,Object value);
	
	public String filterLastID (Class<?> clazz,Map<String,Object> conditions);

	/**
	 * @param query Lucene查询语句
	 * */
	public List<Entity> search(String query,int size);
	
	/**
	 * @param query Lucene查询对象
	 * */
	public List<Entity> search(Query query,int size);
	public List<Relation> searchRelations(Query query, int size);
	public List<Record> searchRecords(Query query, int size);
	public List<Map<String, String>> searchMap(Query query, int size);
	
}
